package com.twu.biblioteca.operation;

import com.twu.biblioteca.model.Movie;
import com.twu.biblioteca.model.Status;
import com.twu.biblioteca.service.MovieService;

import java.util.List;

import static java.lang.String.format;

public class ListMoviesOperation extends Operation {
    private MovieService movieService;

    public void setMovieService(MovieService movieService) {
        this.movieService = movieService;
    }

    @Override
    public String operate(String[] args) {
        String result = "";
        List<Movie> movies = movieService.getAllMovies();
        for (Movie movie : movies) {
            if (movie.getStatus().equals(Status.available)) {
                result += format("|%s|%s|%s|%s|%s",
                        movie.getMovieId(),
                        movie.getMovieName(),
                        movie.getDirector(),
                        movie.getYear(),
                        movie.getRating()) + "\r\n";
            }
        }
        return result;
    }
}
